package com.pisolution.scheduler.runtime.worker.processor;

import com.pisolution.scheduler.core.utils.JsonUtils;
import com.pisolution.scheduler.remote.command.Command;
import com.pisolution.scheduler.remote.command.CommandConverter;
import com.pisolution.scheduler.remote.command.CommandType;

import java.util.Date;

/**
 * 用于工作节点通知管理节点任务执行请求已经接收并完成了执行前的预处理步骤.
 *
 * @author sora
 * @version 0.1.0
 */
public final class TaskAckCommand implements CommandConverter {
    private static final long serialVersionUID = 3957101543882033022L;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (基础属性)
    // -------------------------------------------------------------------------------------------------

    /** 任务实例标识. */
    private int id;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (执行环境)
    // -------------------------------------------------------------------------------------------------

    /** 执行任务的主机网络地址. */
    private String host;

    /** 执行任务的路径. */
    private String executePath;

    /** 任务执行日志的存储路径. */
    private String logPath;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (运行信息)
    // -------------------------------------------------------------------------------------------------

    /** 任务的执行状态. */
    private int status;

    /** 任务开始执行时间. */
    private Date startTime;

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getHost() {
        return this.host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getExecutePath() {
        return this.executePath;
    }

    public void setExecutePath(String executePath) {
        this.executePath = executePath;
    }

    public String getLogPath() {
        return this.logPath;
    }

    public void setLogPath(String logPath) {
        this.logPath = logPath;
    }

    public int getStatus() {
        return this.status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Date getStartTime() {
        return this.startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    // -------------------------------------------------------------------------------------------------
    //  指令转换
    // -------------------------------------------------------------------------------------------------

    @Override
    public Command convert() {
        final Command command = new Command();

        command.setType(CommandType.TASK_ACK_REQUEST);
        command.setBody(JsonUtils.serialize(this));

        return command;
    }
}
